package com.sfac.javaSpringBoot.modules.test.dao;

import com.sfac.javaSpringBoot.modules.test.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface StudentRepository extends JpaRepository<Student,Integer>, JpaSpecificationExecutor<Student> {

    Student findFirstByNameAndEmail(String name,String email);

    //HQL查询语句
    @Query(value="from Student where id=:id")
    Student getStudentById(@Param("id") int id);

    //HQL的新增语句语句，自己定义的方法，弊端是不能返回自增的id
    @Query(nativeQuery=true,value="insert into test-student (name,email,age)" +
            "values(:#{#student.name},:#{#student.email},:#{#student.age},)")
    void insertStudent(@Param("student")Student student);

}
